#include<stdio.h>
#define N 99999999
int book1[N];
int book2[N];
int main()
{
	int n,m,i,temp,count=0;
	scanf("%d%d",&n,&m);getchar();
	while(m--)
	{
		for(i=1;i<=n;i++)
		{
			scanf("%d",&temp);
			if(temp>=N&&book1[temp%N]==0)
			{
				count++;
				book1[temp%N]=1;
			}
			else if(book2[temp]==0)
			{
				count++;
				book2[temp]=1;
			}
		}
	}
	printf("%d\n",count);
	return 0;
 } 
